import com.sun.xml.internal.bind.v2.model.annotation.Quick;

public class QuickSort {
    public static void main(String args[]) {
    int[] a={2,4,5,6,2,1,5};
        QuickSort quickSort = new QuickSort();
        quickSort.Quick(a);
    }

    public void Quick(int[] array){
        int len;
        if (array == null || (len=array.length)==1){
            return;
        }
        Sort(array,0,len-1);
        for (int i : array) {

            System.out.println(i);
        }
    }
    public void Sort(int[] array,int left,int right){

        if (left>right){
            return;
        }
        int base=array[left];
        int temp;
        int i=left,j=right;
        while (i!=j){

            while (array[j]>=base&&i<j){
                j--;
            }
            while (array[i]<=base&&i<j){
                i++;
            }
            if (i<j){
                temp=array[i];
                array[i]=array[j];
                array[j]=temp;
            }
        }
        //交换基数位置
        array[left]=array[j];
        array[j]=base;

        Sort(array,left,i-1);
        Sort(array,i+1,right);

    }

}
